using System;

namespace Test.ConsoleProgram.Algorithm.Solution
{
    [TestDescription("算法: 0011. 盛最多水的容器")]
    public class No0011_MaxArea : AbsBaseTestItem
    {
        public override void OnTest()
        {
            Assert.TestExe(MaxArea, new int[] { 1, 8, 6, 2, 5, 4, 8, 3, 7 }, 49);
        }

        public int MaxArea(int[] height)
        {
            int left = 0, right = height.Length - 1;
            int result = 0;
            while (left < right)
            {
                int leftValue = height[left];
                int rightValue = height[right];
                int area = Math.Min(leftValue, rightValue) * (right - left);
                result = Math.Max(area, result);
                if (leftValue <= rightValue)
                {
                    left++;
                }
                else
                {
                    right--;
                }
            }
            return result;
        }
    }
}
